package logic

import (
	"context"
	"good_srv/good"

	"api/internal/svc"
	"api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type ActiceAddLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewActiceAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ActiceAddLogic {
	return &ActiceAddLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *ActiceAddLogic) ActiceAdd(req *types.ActiveAddResquest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	add, err := l.svcCtx.GoodSrv.ActiveAdd(l.ctx, &good.ActiveAddRequest{
		Title:     req.Title,
		Price:     float32(req.Price),
		Num:       req.Num,
		Image:     req.Image,
		Address:   req.Address,
		Tel:       req.Tel,
		Progress:  int64(req.Produces),
		Countdown: req.Countdown,
	})
	if err != nil {
		return &types.Response{
			Mes:  err.Error(),
			Code: 400,
			Data: nil,
		}, nil
	}
	return &types.Response{
		Mes:  "活动添加成功",
		Code: 200,
		Data: add,
	}, nil
}
